﻿namespace EasyToolkit.ModelDefinition
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using EasyToolkit.BindingTemplates.Definitions.Binding;

    class ModelBoundProperty : IModelProperty
    {
        public IBindingDefinition BindingDefinition
        { get; private set; }

        public string Name
        {
            get { return BindingDefinition.Name; }
        }

        public string Description
        {
            get { return BindingDefinition.Description; }
        }

        #region .ctors and factories
        private ModelBoundProperty(IBindingDefinition bindingDefinition)
        {
            BindingDefinition = bindingDefinition;
        }

        static public IEnumerable<ModelBoundProperty> CreateInstance(Type type)
        {
            List<ModelBoundProperty> ret = new List<ModelBoundProperty>();
            if (type != null)
            {
                List<BindingDefinitionDescription> descriptions = new List<BindingDefinitionDescription>(); 
                List<PropertyInfo> propertyInfos = type.GetProperties().ToList();
                propertyInfos.ForEach(pi => ret.Add(new ModelBoundProperty(BindingDefinitionFactory.CreateInstance(pi))));

                //List<MethodInfo> methodInfos = type.GetMethods().Where(mi => mi.GetParameters().Count() == 0).ToList();
                //methodInfos.ForEach(mi => ret.Add(new ModelBoundProperty(BindingDefinitionFactory.CreateInstance(mi))));
            }
            return ret;
        }
        #endregion
    }
}
